home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / DEV / I-Z / TransSkel.cpt / TinyEdit.pas < prev    next >
Pascal/Delphi Source File  |  1987-01-08  |  4KB  |  204 lines

  1. {    TinyEdit - Minimal TransEdit Demonstration.}
  2.  
  3. {    The project should include TinyEdit.pas (this file), TransEdit.pas,}
  4. {    FakeAlert.pas, TransSkelpas (or a project made from TransSkelpas)}
  5. {    MacPasLib and MacTraps.}
  6.  
  7. {    8 November 1986        Paul DuBois}
  8.  
  9. {    8 January 1987             Ported to LightSpeed Pascal by Owen Hartnett        }
  10. {    Ωhm Software Company, 163 Richard Drive, Tiverton, RI 02878            }
  11.  
  12. PROGRAM TinyEdit;
  13.  
  14.     USES
  15.         TransEditPas, TransSkelPas;
  16.  
  17.     CONST
  18.         aboutAlrt = 1000;    { "About..." alert number }
  19.  
  20.         { File menu item numbers }
  21.  
  22.         new = 1;        { begin new window }
  23.         open = 2;            { open existing file }
  24.         close = 3;            { close window }
  25.         quit = 5;
  26.  
  27.             { Edit menu item numbers }
  28.  
  29.         undo = 1;
  30.         cut = 3;
  31.         copy = 4;
  32.         paste = 5;
  33.         clear = 6;
  34.  
  35.     VAR
  36.         lastFront, editWind : WindowPtr;    { keeps track of front window }
  37.         { non-nil if edit window open }
  38.  
  39.         fileMenu, editMenu : MenuHandle;
  40.  
  41. {    Set File/Edit menu items according to type of front window.}
  42.  
  43. {    The general behavior is:}
  44.  
  45. {    New and Open enabled if an edit window is not open, otherwise they}
  46. {    are disabled.}
  47.  
  48. {    Close enabled when an edit or DA window is in front (i.e.,}
  49. {    when there's a window at all).}
  50.  
  51. {    Undo disabled when the edit window is in front.}
  52.  
  53.     PROCEDURE SetMenus;
  54.  
  55.     BEGIN
  56.         DisableItem(fileMenu, close);    { assume no window at all }
  57.         EnableItem(editMenu, undo);
  58.  
  59.         IF FrontWindow <> NIL THEN
  60.             BEGIN
  61.                 EnableItem(fileMenu, close);
  62.                 IF (IsEWindow(FrontWindow)) THEN    { the edit window's in front }
  63.                     DisableItem(editMenu, undo);
  64.             END;
  65.         IF editWind = NIL THEN
  66.             BEGIN
  67.                 EnableItem(fileMenu, new);
  68.                 EnableItem(fileMenu, open);
  69.             END
  70.         ELSE
  71.             BEGIN
  72.                 DisableItem(fileMenu, new);
  73.                 DisableItem(fileMenu, open);
  74.             END;
  75.     END;
  76.  
  77. {    Got an activate or deactivate.  It doesn't matter which, really.}
  78. {    Set the text menus appropriately for the front window, and draw}
  79. {    the menu bar, as these menus might change state from enabled to}
  80. {    disabled or vice-versa.}
  81.  
  82.  
  83.     PROCEDURE Activate (active : Boolean);
  84.  
  85.     BEGIN
  86.         SetMenus;
  87.     END;
  88.  
  89. {    Close selected from File menu, or close box of edit window was}
  90. {    clicked.}
  91.  
  92.     PROCEDURE myClose;
  93.  
  94.     BEGIN
  95.         IF (EWindowClose(editWind)) THEN
  96.             editWind := NIL;
  97.         SetMenus;
  98.     END;
  99.  
  100. {    Make a new edit window.  Set the title to "Untitled" if not bound}
  101. {    to file, so that the window titling works the same whether}
  102. {    TransEdit is compiled in single or multiple window mode.}
  103.  
  104.     PROCEDURE MakeWind (bindToFile : Boolean);
  105.  
  106.         VAR
  107.             r : Rect;
  108.  
  109.     BEGIN
  110.         SetRect(r, 4, 45, 504, 335);
  111.         editWind := NewEWindow(r, '', false, WindowPtr(-1), true, longint(0), bindToFile);
  112.         IF editWind <> NIL THEN
  113.             BEGIN
  114.                 IF NOT bindToFile THEN
  115.                     SetWTitle(editWind, 'Untitled');
  116.                 ShowWindow(editWind);
  117.             END;
  118.     END;
  119.  
  120. {    File menu handler}
  121.  
  122.     PROCEDURE DoFileMenu (item : integer);
  123.  
  124.         VAR
  125.             theWind : WindowPtr;
  126.             myPeek : WindowPeek;
  127.  
  128.     BEGIN
  129.         theWind := FrontWindow;
  130.         CASE item OF
  131.             new : 
  132.                 MakeWind(false);
  133.             open : 
  134.                 MakeWind(true);
  135.             close : 
  136.                 IF IsEWindow(theWind) THEN
  137.                     myClose
  138.                 ELSE
  139.                     BEGIN
  140.                         myPeek := WindowPeek(theWind);
  141.                         CloseDeskAcc(myPeek^.windowKind);
  142.                     END;
  143.             quit : 
  144.                 IF ClobberEWindows = true THEN
  145.                     SkelWhoa;
  146.             OTHERWISE
  147.         END;
  148.         SetMenus;
  149.     END;
  150.  
  151. {    Handle selection of About… item from Apple menu}
  152.  
  153.     PROCEDURE DoAbout;
  154.  
  155.         VAR
  156.             ignore : integer;
  157.  
  158.     BEGIN
  159.         ignore := Alert(aboutAlrt, NIL);
  160.     END;
  161.  
  162. {    Background procedure.  Check front window, reset menus if it}
  163. {    changes.}
  164.  
  165.     PROCEDURE CheckFront;
  166.  
  167.     BEGIN
  168.         IF FrontWindow <> lastFront THEN
  169.             BEGIN
  170.                 SetMenus;
  171.                 lastFront := FrontWindow;
  172.             END;
  173.     END;
  174.  
  175. BEGIN
  176.     lastFront := NIL;
  177.     editWind := NIL;
  178.  
  179. {    Initialize TransSkel, create menus and install handlers.}
  180.  
  181.     SkelInit;
  182.     TransEditInit;
  183.     SkelApple('About TinyEdit...', @DoAbout);
  184.  
  185.     fileMenu := NewMenu(1000, 'File');
  186.     AppendMenu(fileMenu, 'New/N;Open.../O;(Close/K;(-;Quit/Q');
  187.     SkelMenu(fileMenu, @DoFileMenu, NIL);
  188.  
  189.     editMenu := NewMenu(1001, 'Edit');
  190.     AppendMenu(editMenu, 'Undo/Z;(-;Cut/X;Copy/C;Paste/V;Clear');
  191.     SkelMenu(editMenu, @EWindowEditOp, NIL);
  192.  
  193. {    Do TransEdit-specific setup:  set creator for any files created,}
  194. {    set default event notification procedures for new windows.}
  195.  
  196.     SetEWindowProcs(NIL, NIL, @Activate, @myClose);
  197.  
  198. {    Process events until user quits,}
  199. {    then clean up and exit}
  200.  
  201.     SkelBackground(@CheckFront);
  202.     SkelMain;
  203.     SkelClobber;
  204. END.